import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class Test {
    public static ArrayList<Character> del(String s1, String s2) {
        //创建一个顺序表，接收s1中与s2中不重复的字符
        ArrayList<Character> arrayList = new ArrayList<>();
        //遍历s1
        for (int i = 0; i < s1.length(); i++) {
            //获取对应下标位置的字符
            char ch = s1.charAt(i);
            if (!s2.contains(ch + "")){
                arrayList.add(ch);
            }
        }
        return arrayList;
    }
    public static void main(String[] args) {
        //小练习
        String s1 = "welcome to victim";
        String s2 = "come";
        ArrayList<Character> ret = del(s1, s2);
        for (Character x : ret) {
            System.out.print(x);
        }
    }

    public static void main4(String[] args) {
        //遍历
        List<Integer> list = new ArrayList<>(); //无参构造
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);

        //方式一：sout
        System.out.println(list); //源码中重写了toString方法
        System.out.println("===========================");

        //方式二：for循环
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + " ");
        }
        System.out.println();

        for (Integer x : list) {
            System.out.print(x + " ");
        }
        System.out.println();
        System.out.println("===========================");

        /**
         * 方式三：迭代器
         * Iterator 和 ListIterator都可以遍历顺序表，ListIterator还可以逆序遍历
         */
        Iterator<Integer> iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.print(iterator.next() + " ");
        }
        System.out.println();

        ListIterator<Integer> listIterator = list.listIterator();
        while (listIterator.hasNext()) {
            System.out.print(listIterator.next() + " ");
        }
        System.out.println();

        //使用ListIterator逆序输出
        ListIterator<Integer> listIterator1 = list.listIterator(list.size());
        while (listIterator1.hasPrevious()) {
            System.out.print(listIterator1.previous() + " ");
        }
        System.out.println();
    }




    public static void main3(String[] args) {
        //方法测试
        List<Integer> list = new ArrayList<>(); //无参构造
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        System.out.println(list); //[1, 2, 3, 4, 5]

        //addAll:添加一个顺序表中的所有元素
        list.addAll(list);
        System.out.println(list); //[1, 2, 3, 4, 5, 1, 2, 3, 4, 5]

        //使用remove进行删除时，如果想要删除值，需要通过new关键字
        list.remove(2);
        System.out.println(list); //[1, 2, 4, 5, 1, 2, 3, 4, 5]
        list.remove(new Integer(2));
        System.out.println(list); //[1, 4, 5, 1, 2, 3, 4, 5]

        //使用subList对顺序表进行截取
        List<Integer> list1 = list.subList(1, 3); //左闭右开区间
        System.out.println(list1); //[4, 5]
        //当修改截取到的顺序表中的值时，原顺序表对应位置的值也会被修改
        list1.set(1, 666);
        System.out.println(list1); //[4, 666]
        System.out.println(list); //[1, 4, 666, 1, 2, 3, 4, 5]
    }




    public static void main2(String[] args) {
        //构造
        ArrayList<Integer> arrayList = new ArrayList<>(); //无参构造
        List<Integer> list = new ArrayList<>(2); //指定顺序表容量
        List<Integer> list1 = new ArrayList<>(list); //参数为 顺序表
    }




    public static void main1(String[] args) {
        //模拟实现测试
        MyArrayList myArrayList = new MyArrayList(2);
        myArrayList.add(1);
        myArrayList.add(2);
        myArrayList.add(3);
        myArrayList.add(4);
        myArrayList.add(5);
        myArrayList.display(); //1 2 3 4 5
        myArrayList.add(1, 99);
        myArrayList.display(); //1 99 2 3 4 5
        System.out.println(myArrayList.contains(2)); //true
        System.out.println(myArrayList.contains(66)); //false
        System.out.println(myArrayList.indexOf(2)); //2
        System.out.println(myArrayList.get(1)); //99
        myArrayList.set(1, 88);
        myArrayList.display(); //1 88 2 3 4 5
        System.out.println(myArrayList.size()); //6
        myArrayList.remove(88);
        myArrayList.display(); //1 2 3 4 5
        System.out.println("======");
        myArrayList.clear();
        myArrayList.display();
        System.out.println("======");
    }
}
